<template>
  <div class="screen">
    <div class="region">
      <template v-if="!isFinished">
        <p class="region-title">{{ bounds.width }} * {{ bounds.height }}</p>
        <p class="region-tips">选定区域后，点击下方按钮后退出选择，可在主界面中开始录制</p>
        <div class="region-btns">
          <n-button type="error" @click="selectRegion">确定选择</n-button>
        </div>
      </template>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, h, ref, Component, } from 'vue'
export default defineComponent({
  name: 'Region',
  setup(){
    return {
      bounds: ref({
        x: 0,
        y: 0,
        width: 1920,
        height: 1080
      }),
      isFinished: ref(false)
    }
  },
  beforeMount() {
    window.electron.ipcRenderer.on('main-to-renderer', (e, data) => {
      const event = data.data
      console.log(event)
      if(data.name === 'window-resized'){
        this.bounds = event
      }
    })
  },
  methods: {
    selectRegion(){
      this.isFinished = true
      window.electron.ipcRenderer.invoke("renderer-to-main", {
        name: 'select-region-finished',
        event: 'event',
        args: null
      })
    }
  }
})
</script>

<style lang="less" scoped>
.screen{
  position: relative;
  width: 100vw;
  height: 100vh;
  user-select: none;
  -webkit-app-region: drag;
  border: #cc3344 3px solid;
  box-sizing: border-box;
  .region{
    color: #cc3344;
    text-align: center;
    user-select: none;
    -webkit-app-region: no-drag;
    font-weight: bold;
    position: absolute;
    transform: translateX(-50%) translateY(-50%);
    left: 50%;
    top: 50%;
    z-index: 1;
    .region-title{
      font-size: 50px;
    }
    .region-tips{
      font-size: 20px;
    }
    .region-btns{
      margin-top: 15px;
    }
  }
}
</style>
